@page "/_Admin/FrameworkTenant/Create"
@using WalkingTec.Mvvm.Mvc.Admin.ViewModels.FrameworkTenantVMs
@inherits BasePage


<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit">
    <Row ItemsPerRow="ItemsPerRow.Two">
        <BootstrapInput @bind-Value="@Model.Entity.TCode" />
        <BootstrapInput @bind-Value="@Model.Entity.TName" />
        <BootstrapInput @bind-Value="@Model.Entity.TDb" />
        <Select @bind-Value="@Model.Entity.TDbType" />
        <BootstrapInput @bind-Value="@Model.Entity.DbContext" />
        <BootstrapInput @bind-Value="@Model.Entity.TDomain" />
        <Select @bind-Value="@Model.Entity.EnableSub" Items="WtmBlazor.GlobalSelectItems.BoolItems"/>
        <Select @bind-Value="@Model.Entity.Enabled" Items="WtmBlazor.GlobalSelectItems.BoolItems"/>
    </Row>

    <Row ItemsPerRow="ItemsPerRow.Two">
        <Select @bind-Value="@Model.AdminRoleCode" Items="@AllParents"  />
        <div style="padding-top:35px;">@WtmBlazor.Localizer["_Admin.TenantRole"]</div>
    </Row>
    <div class="modal-footer table-modal-footer">
        <Button Color="Color.Primary" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Close"]" OnClick="OnClose" />
        <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="@WtmBlazor.Localizer["Sys.Create"]" IsAsync="true" />
    </div>
</ValidateForm>

@code {
    private FrameworkTenantVM Model = new FrameworkTenantVM();

    private ValidateForm vform { get; set; }
    private List<SelectedItem> AllParents = new List<SelectedItem>();

    protected override async Task OnInitializedAsync()
    {
        AllParents = await WtmBlazor.Api.CallItemsApi("/api/_account/GetFrameworkRoles", placeholder: WtmBlazor.Localizer["Sys.PleaseSelect"]);
    }

    private async Task Submit(EditContext context)
    {
        await PostsForm(vform, "/api/_FrameworkTenant/add", (s) => "Sys.OprationSuccess");
    }

    public void OnClose()
    {
        CloseDialog();
    }

}

